# -*- coding: utf-8 -*-
# © 2018 QYT Technology
# Authored by: Zhao Xingtao (zxt50330@gmail.com)
import time
from bills import db


class PlanRecord(db.Model):
    """记录基类"""
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    type = db.Column(db.Integer, index=True, default=100, nullable=False)

    content = db.Column(db.Text)
    remark = db.Column(db.Text, doc=u'备注')

    ctime = db.Column(db.Integer, nullable=False, default=time.time, index=True, doc=u'创建时间')
    utime = db.Column(db.Integer, nullable=False, default=time.time, onupdate=time.time, doc='更新时间')
    rtime = db.Column(db.Integer, nullable=True, doc='本记录时间')

    __type_mapper__ = (
        (100, "fitness"),
    )
    __mapper_args__ = {
        'polymorphic_on': type,
        'polymorphic_identity': None
    }

    def __repr__(self):
        return (u'<PlanRecord[%s]>' % (self.name))

    @property
    def type_name(self):
        return (dict(self.__type_mapper__)[self.type])
